package com.platform.framework.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.platform.framework.util.pub.ContextUtil;


/**
 * 自定义的ContextLoader（线程注入使用）
 * @author ly-liugaoyang
 * @create_date 2016年10月20日
 */
@SuppressWarnings("unused")
public class MyContextLoaderListener extends ContextLoaderListener {
	
	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		ServletContext context = event.getServletContext();		
		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		ContextUtil.setContext(ctx);

	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		ServletContext context = event.getServletContext();
		Object num = context.getAttribute("visitTotal");
		super.contextDestroyed(event);
	}
}